package c.a.a.b0.l;

import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import b.f.e;
import c.a.a.b0.j.b;
import c.a.a.e0.g;
import c.a.a.f;
import c.a.a.l;
import c.a.a.q;
import c.a.a.z.c.a;
import c.a.a.z.c.p;
import com.pgl.sys.ces.out.ISdkLite;
import java.util.ArrayList;
import java.util.List;

/* compiled from: CompositionLayer */
public class c extends b {
    public final RectF A = new RectF();
    public Paint B = new Paint();
    public a<Float, Float> x;
    public final List<b> y = new ArrayList();
    public final RectF z = new RectF();

    public c(l lVar, e eVar, List<e> list, f fVar) {
        int i;
        super(lVar, eVar);
        b bVar = eVar.s;
        if (bVar != null) {
            a a = bVar.a();
            this.x = a;
            e(a);
            this.x.a.add(this);
        } else {
            this.x = null;
        }
        e eVar2 = new e(fVar.i.size());
        int size = list.size() - 1;
        b bVar2 = null;
        while (true) {
            i = 0;
            if (size < 0) {
                break;
            }
            b cVar;
            e eVar3 = (e) list.get(size);
            int ordinal = eVar3.e.ordinal();
            if (ordinal == 0) {
                cVar = new c(lVar, eVar3, (List) fVar.c.get(eVar3.g), fVar);
            } else if (ordinal == 1) {
                cVar = new h(lVar, eVar3);
            } else if (ordinal == 2) {
                cVar = new d(lVar, eVar3);
            } else if (ordinal == 3) {
                cVar = new f(lVar, eVar3);
            } else if (ordinal == 4) {
                cVar = new g(lVar, eVar3);
            } else if (ordinal != 5) {
                StringBuilder g = c.b.a.a.a.g("Unknown layer type ");
                g.append(eVar3.e);
                c.a.a.e0.c.b(g.toString());
                cVar = null;
            } else {
                cVar = new i(lVar, eVar3);
            }
            if (cVar != null) {
                eVar2.h(cVar.o.d, cVar);
                if (bVar2 != null) {
                    bVar2.r = cVar;
                    bVar2 = null;
                } else {
                    this.y.add(0, cVar);
                    i = eVar3.u.ordinal();
                    if (i == 1 || i == 2) {
                        bVar2 = cVar;
                    }
                }
            }
            size--;
        }
        while (i < eVar2.i()) {
            b bVar3 = (b) eVar2.e(eVar2.g(i));
            if (bVar3 != null) {
                b bVar4 = (b) eVar2.e(bVar3.o.f);
                if (bVar4 != null) {
                    bVar3.s = bVar4;
                }
            }
            i++;
        }
    }

    public void b(RectF rectF, Matrix matrix, boolean z) {
        super.b(rectF, matrix, z);
        for (int size = this.y.size() - 1; size >= 0; size--) {
            this.z.set(0.0f, 0.0f, 0.0f, 0.0f);
            ((b) this.y.get(size)).b(this.z, this.m, true);
            rectF.union(this.z);
        }
    }

    public <T> void i(T t, c.a.a.f0.c<T> cVar) {
        this.v.c(t, cVar);
        if (t != q.A) {
            return;
        }
        if (cVar == null) {
            a aVar = this.x;
            if (aVar != null) {
                aVar.i(null);
                return;
            }
            return;
        }
        p pVar = new p(cVar, null);
        this.x = pVar;
        pVar.a.add(this);
        e(this.x);
    }

    public void l(Canvas canvas, Matrix matrix, int i) {
        RectF rectF = this.A;
        e eVar = this.o;
        rectF.set(0.0f, 0.0f, (float) eVar.o, (float) eVar.p);
        matrix.mapRect(this.A);
        Object obj = (!this.n.r || this.y.size() <= 1 || i == ISdkLite.REGION_UNSET) ? null : 1;
        if (obj != null) {
            this.B.setAlpha(i);
            g.f(canvas, this.A, this.B, 31);
        } else {
            canvas.save();
        }
        if (obj != null) {
            i = ISdkLite.REGION_UNSET;
        }
        for (int size = this.y.size() - 1; size >= 0; size--) {
            if (!this.A.isEmpty() ? canvas.clipRect(this.A) : true) {
                ((b) this.y.get(size)).g(canvas, matrix, i);
            }
        }
        canvas.restore();
        c.a.a.c.a("CompositionLayer#draw");
    }

    public void p(c.a.a.b0.e eVar, int i, List<c.a.a.b0.e> list, c.a.a.b0.e eVar2) {
        for (int i2 = 0; i2 < this.y.size(); i2++) {
            ((b) this.y.get(i2)).f(eVar, i, list, eVar2);
        }
    }

    public void q(float f) {
        super.q(f);
        if (this.x != null) {
            f = ((((Float) this.x.e()).floatValue() * this.o.b.m) - this.o.b.k) / (this.n.b.c() + 0.01f);
        }
        if (this.x == null) {
            e eVar = this.o;
            f -= eVar.n / eVar.b.c();
        }
        float f2 = this.o.m;
        if (f2 != 0.0f) {
            f /= f2;
        }
        int size = this.y.size();
        while (true) {
            size--;
            if (size >= 0) {
                ((b) this.y.get(size)).q(f);
            } else {
                return;
            }
        }
    }
}
